﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;

namespace GDoc.Tests
{
    public class TestHttpContextLifeManager<T> : LifetimeManager, IDisposable
    {
        public static Dictionary<string, object> HttpContextCurrent = new Dictionary<string,object>();

        public override object GetValue()
        {
            if(HttpContextCurrent.ContainsKey(typeof(T).AssemblyQualifiedName))
                return HttpContextCurrent[typeof(T).AssemblyQualifiedName];
            return null;
        }

        public override void RemoveValue()
        {
            HttpContextCurrent.Remove(typeof(T).AssemblyQualifiedName);
        }

        public override void SetValue(object newValue)
        {
            HttpContextCurrent[typeof(T).AssemblyQualifiedName] = newValue;
        }

        public void Dispose()
        {
            HttpContextCurrent.Clear();
        }
    }
}
